package com.yodawnla.attackTitan2;

import org.anddev.andengine.entity.IEntity;
import org.anddev.andengine.entity.modifier.AlphaModifier;
import org.anddev.andengine.entity.modifier.IEntityModifier.IEntityModifierListener;
import org.anddev.andengine.entity.modifier.MoveYModifier;
import org.anddev.andengine.entity.modifier.SequenceEntityModifier;
import org.anddev.andengine.util.modifier.IModifier;

import com.yodawnla.attackTitan2.scene.GameScene;
import com.yodawnla.lib.util.widget.YoText;

public class DamageText extends YoText
{
	GameScene mScene;
	boolean mIsShow = false;	
	IEntityModifierListener mListener;
	
	public DamageText(float pX, float pY, String stroke30, String pText, int pCharactersMaximum, GameScene scene)
	{
		super(pX, pY, stroke30, pText, pCharactersMaximum);
		
		mScene = scene;
		
		mListener = new IEntityModifierListener()
		{
			public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem)
			{
			}

			public void onModifierFinished(IModifier<IEntity> pModifier, final IEntity pItem)
			{
				pItem.setAlpha(0);
				pItem.setVisible(false);
				setIsShow(false);
			}
		};
	}
	
	public void showDamageText(int damage, float pX, float pY)
	{
		setText("" + damage);
		setVisible(true);
		clearEntityModifiers();
		registerEntityModifier(new SequenceEntityModifier(new AlphaModifier(0.2f, 0, 1), new AlphaModifier(0.2f, 1, 1), new AlphaModifier(0.2f, 1, 0)));
		setPosition(pX, pY);
		registerEntityModifier(new MoveYModifier(0.6f, pY, pY - 10, mListener));
	}
	
	public void setIsShow(boolean isShow)
	{
		mIsShow = isShow;
	}
	
	public boolean getIsShow()
	{
		return mIsShow;
	}
	
	public void resetText()
	{
		setVisible(false);
		clearEntityModifiers();
		setAlpha(0);
	}
}